package com.lzx.adx.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lzs.adx.commmon.service.impl.CrudServiceImpl;
import com.lzx.adx.report.cache.ProductLimitLocalCache;
import com.lzx.adx.report.dao.WphLimitDao;
import com.lzx.adx.report.dto.WphLimitDTO;
import com.lzx.adx.report.entity.WphLimitEntity;
import com.lzx.adx.report.service.WphLimitService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class WphLimitServiceImpl extends CrudServiceImpl<WphLimitDao, WphLimitEntity, WphLimitDTO> implements WphLimitService {
    @Override
    public QueryWrapper<WphLimitEntity> getWrapper(Map<String, Object> params) {
        String product = (String)params.get("product");

        QueryWrapper<WphLimitEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(product), "product", product);

        return wrapper;
    }

    @Override
    public void sysnCacheToDb() {
        List<WphLimitDTO> list = this.list(new HashMap<>());

        for(WphLimitDTO wphLimitDTO:list){
            ProductLimitLocalCache.getInstance().put(wphLimitDTO.getProduct(),wphLimitDTO.getPrice());
        }
    }
}
